%%-*- mode: erlang -*-
%% EMQ X R3.0 config mapping

{mapping, "web.hook.url", "emqx_web_hook.url", [
  {datatype, string}
]}.

{mapping, "web.hook.headers.$name", "emqx_web_hook.headers", [
  {datatype, string}
]}.

{mapping, "web.hook.body.encoding_of_payload_field", "emqx_web_hook.encoding_of_payload_field", [
  {default, plain},
  {datatype, {enum, [plain, base62, base64]}}
]}.

{mapping, "web.hook.ssl.cacertfile", "emqx_web_hook.cacertfile", [
  {default, ""},
  {datatype, string}
]}.

{mapping, "web.hook.ssl.certfile", "emqx_web_hook.certfile", [
  {default, ""},
  {datatype, string}
]}.

{mapping, "web.hook.ssl.keyfile", "emqx_web_hook.keyfile", [
  {default, ""},
  {datatype, string}
]}.

{mapping, "web.hook.ssl.verify", "emqx_web_hook.verify", [
  {default, false},
  {datatype, {enum, [true, false]}}
]}.

{mapping, "web.hook.ssl.server_name_indication", "emqx_web_hook.server_name_indication", [
  {datatype, string}
]}.

{mapping, "web.hook.pool_size", "emqx_web_hook.pool_size", [
  {default, 32},
  {datatype, integer}
]}.

{mapping, "web.hook.rule.client.connect.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.client.connack.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.client.connected.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.client.disconnected.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.client.subscribe.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.client.unsubscribe.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.session.subscribed.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.session.unsubscribed.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.session.terminated.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.message.publish.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.message.acked.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{mapping, "web.hook.rule.message.delivered.$name", "emqx_web_hook.rules", [
  {datatype, string}
]}.

{translation, "emqx_web_hook.headers", fun(Conf) ->
  Headers = cuttlefish_variable:filter_by_prefix("web.hook.headers", Conf),
  [{K, V} || {[_, _, _, K], V} <- Headers]
end}.

{translation, "emqx_web_hook.rules", fun(Conf) ->
  Hooks = cuttlefish_variable:filter_by_prefix("web.hook.rule", Conf),
  lists:map(
    fun({[_, _, _,Name1,Name2, _], Val}) -> 
	  {lists:concat([Name1,".",Name2]), Val}
	end, Hooks)
end}.
